package nl.ru.rd.facedetection.nnbfd.neuralnetwork;

/**
 * A NeuralLayer which can be trained using backpropagation.
 * 
 * @author Wouter Geraedts (s0814857)
 */
public interface Backpropagatable extends Layer
{
	/**
	 * Update the difference in errors (delta) for all Neurons, when the targets for the Neurons are known.
	 * 
	 * Only applicable when this is the last layer in the network, resulting direct outputs.
	 * 
	 * Usually used during the first pass in backpropagation.
	 * 
	 * @param targets
	 *            The activations the Neurons should return if the network was perfectly trained.
	 */
	public void updateDeltas(double[] targets);

	/**
	 * Update the difference in errors (delta) for all Neurons.
	 * 
	 * Usually used during the first pass in backpropagation.
	 */
	public void updateDeltas();

	/**
	 * Update the weights of this layer.
	 * 
	 * Usually used during the second pass in backpropagation.
	 * 
	 * @param learningRate
	 *            The rate by which to learn, usually between 0.05 and 0.5.
	 */
	public void updateWeights(double learningRate);

	/**
	 * Calculate the sum of the products of errorDeltas and weights of a specific Node in a previous Layer.
	 * 
	 * @param previousLayer
	 *            The previous Layer of the Node for which the error sum should be calculated. Used when dealing with multiple previousLayers.
	 * @param i
	 *            The Node for which the error sum should be calculated.
	 * @return The sum of the products of errorDeltas and weights of a specific Node in a previous Layer.
	 */
	public double calculateErrorSum(Layer previousLayer, int i);
}
